public class test2 {
    class Solution {
        public List<String> summaryRanges(int[] nums) {
            List<String> res = new ArrayList<>();
            int i = 0;
            for(int j = 0;j<nums.length;j++){
                if(j+1==nums.length || nums[j]+1!=nums[j+1]){
                    //不符合+1递增才更新区间，换i
                    StringBuilder sb = new StringBuilder();
                    sb.append(nums[i]);
                    if(i!=j){
                        sb.append("->").append(nums[j]);
                    }
                    res.add(sb.toString());
                    i = j+1;
                }
            }
            return res;
        }
    }
}
